package com.ajk.server.dao;
import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

import com.ajk.server.dao.provider.FriendPatientEventDayProvider;
import com.ajk.server.model.FriendPatientEventDay;
import com.ajk.server.model.query.FriendPatientEventDayQuery;
/**
 * 亲友健康数据-每天只记录一条  <br>
 * t_friend_patient_event_day <br>
 * v1.0 2016-05-22
 */
public interface FriendPatientEventDayMapper {

	/**
	 *根据id删除 亲友健康数据-每天只记录一条
	 */
	@Delete("delete from t_friend_patient_event_day where id=#{id}")
	public Integer deleteById(Integer id);

	/**
	 * 批量新增 亲友健康数据-每天只记录一条
	 */
	@InsertProvider(method="batchInsert",type=FriendPatientEventDayProvider.class)
	@Options(useGeneratedKeys=true,keyColumn="id",keyProperty="list[0].id")
	public Integer batchInsert(List<? extends FriendPatientEventDay> friendPatientEventDays);

	/**
	 * 新增 亲友健康数据-每天只记录一条
	 */
	@InsertProvider(method="insert",type=FriendPatientEventDayProvider.class)
	@Options(useGeneratedKeys=true)
	public Integer insert(FriendPatientEventDay domain);


	/**
	 *更新 亲友健康数据-每天只记录一条
	 */
	@UpdateProvider(method="update",type=FriendPatientEventDayProvider.class)
	public Integer update(FriendPatientEventDay domain);

	/**
	 *根据ID查询 亲友健康数据-每天只记录一条
	 */
	@Select("select * from t_friend_patient_event_day where id=#{id}")
	public FriendPatientEventDay findById(Integer id);

	/**
	 *通过query 查询 亲友健康数据-每天只记录一条
	 */
	@SelectProvider(method="findByQuery",type=FriendPatientEventDayProvider.class)
	public List<FriendPatientEventDay> findByQuery(FriendPatientEventDayQuery query);

	/**
	 *通过query count总条数
	 */
	@SelectProvider(method="countByQuery",type=FriendPatientEventDayProvider.class)
	public Integer countByQuery(FriendPatientEventDayQuery query);

	/**
	 * 通过ids查询
	 */
	@SelectProvider(method="findByIds",type=FriendPatientEventDayProvider.class)
	public List<FriendPatientEventDay> findByIds(List<Integer> ids);

	@Select("select * from t_friend_patient_event_day where friend_id=#{friendId} and category_id=#{categoryId} and date(action_time) = date(#{actionTime}) order by id desc limit 1")
	public FriendPatientEventDay findByCategoryIdAndActionTime(@Param("friendId") Integer friendId,@Param("categoryId") Integer categoryId,@Param("actionTime") Date actionTime);

	//获取最近的一条
	@Select("select * from t_friend_patient_event_day where friend_id=#{friendId} and category_id=#{categoryId} order by action_time desc limit 1")
	public FriendPatientEventDay findLastByCategoryId(@Param("friendId") Integer friendId,@Param("categoryId") Integer categoryId);

	@Select("select * from t_friend_patient_event_day where friend_id=#{friendId} and category_id=#{categoryId} order by action_time desc limit #{limit}")
	public List<FriendPatientEventDay> findLastNByFriendId(@Param("friendId") Integer friendId,@Param("limit") Integer limit,@Param("categoryId") Integer categoryId);

	@Select("select * from t_friend_patient_event_day where category_id=#{categoryId}")
	public List<FriendPatientEventDay> findAllPatientEventDayByCategoryId(@Param("categoryId") Integer categoryId);

}	